package com.zhuozhou.jdyc.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.zhuozhou.jdyc.api.ApplicationHelper;
import com.zhuozhou.jdyc.util.log.LogUtil;
import com.zhuozhou.jdyc.util.networkTools.NetworkStateUtil;


/**
 * Created by 方舟 on 2016/12/29.
 * 自定义广播接收器，监听网络状态是否发生改变
 */
public class NetworkStateReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        ApplicationHelper.getInstance().getMutableLiveData().setValue(null);
        if (NetworkStateUtil.isWifi(context)) {
            LogUtil.show("已连接到无线网络");
        } else if (NetworkStateUtil.isMobile(context)) {
            LogUtil.show("已连接到数据流量网络");
        } else if (!NetworkStateUtil.isConnected(context)) {
            LogUtil.show("没有网络");
        } else {
            LogUtil.show("其他情况");
        }
    }

}
